package com.dayatang.hrm.compensation.domain;

import java.util.Date;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

import com.dayatang.commons.domain.InstanceFactory;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("4")
public class FloatingEmployeeSalaryParameterSetting extends
		SalaryParameterSetting {

	/**
	 * 
	 */
	private static final long serialVersionUID = -235843955379416448L;

	private static FloatingEmployeeSalaryParameterSettingRepository floatingEmployeeSalaryParameterSettingRepository;

	public FloatingEmployeeSalaryParameterSetting() {
	}

	public FloatingEmployeeSalaryParameterSetting(
			FloatingEmployeeSalaryParameter parameter) {
		this();
		setSalaryParameter(parameter);
	}

	public static FloatingEmployeeSalaryParameterSettingRepository getFloatingEmployeeSalaryParameterSettingRepository() {
		if (floatingEmployeeSalaryParameterSettingRepository == null) {
			floatingEmployeeSalaryParameterSettingRepository = InstanceFactory
					.getInstance(FloatingEmployeeSalaryParameterSettingRepository.class);
		}
		return floatingEmployeeSalaryParameterSettingRepository;
	}

	public static void setFloatingEmployeeSalaryParameterSettingRepository(
			FloatingEmployeeSalaryParameterSettingRepository floatingEmployeeSalaryParameterSettingRepository) {
		FloatingEmployeeSalaryParameterSetting.floatingEmployeeSalaryParameterSettingRepository = floatingEmployeeSalaryParameterSettingRepository;
	}

	/*
	 * =======================================
	 * 
	 * action
	 * 
	 * ========================================
	 */

	public boolean isNameAlreadyUsedByOtherInSameSalaryAccountSuite(
			String name, Date fromDate, Date toDate) {
		if (isNew()) {
			return getFloatingEmployeeSalaryParameterSettingRepository()
					.isNameAlreadyUsedExceptSelf(name, fromDate, toDate, null);
		} else {
			return getFloatingEmployeeSalaryParameterSettingRepository()
					.isNameAlreadyUsedExceptSelf(name, fromDate, toDate, this);
		}
	}

	public static FloatingEmployeeSalaryParameterSetting init(
			FloatingEmployeeSalaryParameter parameter) {
		return new FloatingEmployeeSalaryParameterSetting(parameter);
	}

	public static FloatingEmployeeSalaryParameterSetting get(
			FloatingEmployeeSalaryParameter parameter, Date queryDate) {
		return getFloatingEmployeeSalaryParameterSettingRepository().get(
				parameter, queryDate);
	}

	@Override
	public SalaryParameterSetting getNewInstance(SalaryParameter salaryParameter) {
		return new FloatingEmployeeSalaryParameterSetting(
				(FloatingEmployeeSalaryParameter) salaryParameter);
	}

}
